<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <canvas width="1500" height="500"></canvas>
    <script>
        let cv = document.querySelector('canvas')
        if (cv.getContext) {
            let c = cv.getContext('2d')
            let startPoint = 50
            let speed = 15
            // c.strokeStyle = '#ddd'
            let f = function () {
                //清除画布


                if (startPoint >= 1300) {
                    window.cancelAnimationFrame(f)
                } else {
                    c.clearRect(0, 0, 1500, 500)
                    // 运动点
                    startPoint += speed/10
                    // 画圆
                    c.beginPath()
                    c.arc(startPoint, 100, 50, 0, Math.PI * 2)
                    c.closePath()
                    c.stroke()
                }
                // 动画请求
                requestAnimationFrame(f)
            }
            f()

        }
    </script>
</body>

</html>